﻿import { NgModule } from '@angular/core';
import { NavigationEnd, Router, RouterModule } from '@angular/router';
import { WorkStationComponent } from './work-station/work-station.component';
import { ProcessComponent } from './process/process.component';
import { TemplateComponent } from './template/template.component';
import { RequestComponent } from './request/request.component';
import { HostDashboardComponent } from './dashboard/host-dashboard.component';
import { WorkingTeamComponent } from './worker/working-team.component';
import { DistributeComponent } from './distribute/distribute.component';

@NgModule({
    imports: [
        RouterModule.forChild([
            {
                path: '',
                children: [
                    { path: 'dashboard', component: HostDashboardComponent, data: { permission: 'Pages.Duct.Process' } },
                    { path: 'workstation', component: WorkStationComponent, data: { permission: 'Pages.Duct.WorkStation' } },
                    { path: 'process', component: ProcessComponent, data: { permission: 'Pages.Duct.Process' } },
                    { path: 'template', component: TemplateComponent, data: { permission: 'Pages.Duct.Template' } },
                    { path: 'request', component: RequestComponent, data: { permission: 'Pages.Duct.Request' } },
                    { path: 'worker', component: WorkingTeamComponent, data: { permission: 'Pages.Duct.WorkStation' } },
                    { path: 'distribute', component: DistributeComponent, data: { permission: 'Pages.Duct.WorkStation' } },
                ]
            }
        ])
    ],
    exports: [
        RouterModule
    ]
})
export class DuctRoutingModule {

    constructor(
        private router: Router
    ) {
        router.events.subscribe((event) => {
            if (event instanceof NavigationEnd) {
                window.scroll(0, 0);
            }
        });
    }
}
